export default function formatTime(stringTime: string) {
    //将字符串转换成时间格式
    const timePublish = new Date(stringTime);
    const timeNow = new Date();
    const minute = 1000 * 60;
    const hour = minute * 60;
    const day = hour * 24;
    const month = day * 30;
    const year = month * 12;
    const diffValue = timeNow.getTime() - timePublish.getTime();
    const diffMonth = diffValue / month;
    const diffWeek = diffValue / (7 * day);
    const diffDay = diffValue / day;
    const diffHour = diffValue / hour;
    const diffMinute = diffValue / minute;
    const diffYear = diffValue / year;
    let result = null;
    if (diffValue < 0) {
        result = '刚刚';
    } else if (diffYear > 1) {
        result = diffYear.toFixed() + '年前';
    } else if (diffMonth > 1) {
        result = diffMonth.toFixed() + '月前';
    } else if (diffWeek > 1) {
        result = diffWeek.toFixed() + '周前';
    } else if (diffDay > 1) {
        result = diffDay.toFixed() + '天前';
    } else if (diffHour > 1) {
        result = diffHour.toFixed() + '小时前';
    } else if (diffMinute > 1) {
        result = diffMinute.toFixed() + '分钟前';
    } else {
        result = '刚刚';
    }
    return result;
}
